package com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.view;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.base.BaseActivity;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.contract.ICaptureActivityContract;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.logic.persenter.CapturePersenter;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.third.Eyes;
import com.hzdesk.media.matvector.koreabatch.client.my_paperless.utils.VirtualButtonsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bingoogolapple.qrcode.core.QRCodeView;
import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder;
import cn.bingoogolapple.qrcode.zxing.ZXingView;

public class CaptureActivity extends AppCompatActivity implements ICaptureActivityContract.ICaptureActivityView,QRCodeView.Delegate{
    private String TAG=CaptureActivity.class.getSimpleName();

    @BindView(R.id.activity_capture_iv_back)
    ImageView activityCaptureIvBack;
    @BindView(R.id.activity_capture_re_top)
    RelativeLayout activityCaptureReTop;
    private ZXingView activityCaptureZxingview;

    private CapturePersenter capturePersenter=new CapturePersenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: ");
        Eyes.setStatusBarColor(this, 0xffffff);
        VirtualButtonsUtils.hideNavKey(this);
        setContentView(R.layout.activity_capture_activity);
        activityCaptureZxingview=findViewById(R.id.activity_capture_zxingview);
        activityCaptureZxingview.setDelegate(this);
        capturePersenter.initView(activityCaptureZxingview,this);
        ButterKnife.bind(this);
        
    }

    @OnClick(R.id.activity_capture_iv_back)
    public void onViewClicked() {
        capturePersenter.OnClickedBack();

    }

    @Override
    protected void onStart() {
        super.onStart();
        capturePersenter.onStart();
    }

    @Override
    protected void onStop() {
        capturePersenter.onStop();
        super.onStop();
    }


    @Override
    public void vibrate() {
        Vibrator vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
        vibrator.vibrate(200);
    }

    @Override
    public void toSetResult(int resultCode, Intent data) {
        setResult(resultCode,data);
        finish();
    }

    @Override
    public void onScanQRCodeSuccess(String result) {
        capturePersenter.onScanQRCodeSuccess(result);

    }

    @Override
    public void onScanQRCodeOpenCameraError() {
        capturePersenter.onScanQRCodeOpenCameraError();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        capturePersenter.OnClickedBack();
    }


    @Override
    protected void onDestroy() {
        capturePersenter.onDestroy();
        super.onDestroy();
    }
}
